﻿using RightControl.Common;
using RightControl.IRepository;
using RightControl.IService;
using RightControl.Model;
using System.Collections.Generic;

namespace RightControl.Service {
    public class SubProductService : BaseService<SubProduct>, ISubProductService {
        public ISubProductRepository repository { get; set; }

        public int SaveSubProducts(IEnumerable<SubProduct> entitys) {
            return repository.SaveSubProducts(entitys);
        }

        public int UpdateSubProducts(IEnumerable<SubProduct> entitys) {
            return repository.UpdateSubProducts(entitys);
        }


        public dynamic GetListByFilter(SubProduct filter, PageInfo pageInfo) {
            string _where = " where 1=1";
            _where += string.Format(" and ProductId = {0}", filter.ProductId);
            return GetListByFilter(filter, pageInfo, _where);
        }

        public List<SubProduct> GetSubProductList(SubProduct filter, PageInfo pageInfo) {
            List<SubProduct> subProdList = new List<SubProduct>();
       
            dynamic subProdRet = GetListByFilter(filter, pageInfo);
            if (subProdRet != null && subProdRet.count > 0) {
                subProdList = subProdRet.data as List<SubProduct>;
            }
            return subProdList;
        }

        public bool DeleteByProdcutId(int productId) {
            string _where = " where 1=1";
            _where += string.Format(" and ProductId = {0}", productId);
           
            return DeleteByWhere(_where);
        }

        //SELECT DISTINCT(Color) as Color FROM `sub_product`
        //where ProductId = 269;
    }
}